//
//  RootViewController.m
//  Faner
//
//  Created by apple on 15/10/26.
//  Copyright © 2015年 lanou3g.com蓝鸥科技有限公司. All rights reserved.
//

#import "RootViewController.h"
#import "TravelMainViewController.h"
#import "HQCollectionViewController.h"
@interface RootViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIButton *tripBtn;
@property (nonatomic, strong) UIButton *radioBtn;
@property (nonatomic, strong) UIButton *eyesBtn;
@property (nonatomic, strong) UIButton *magazineBtn;
@property (nonatomic, strong) UIButton *aboutMeBtn;
@property (nonatomic, strong) UIScrollView *mainScrollview;
@property (nonatomic, strong) UIPageControl *pageControl;
@property (nonatomic, strong) UIButton *startBtn;
@end

@implementation RootViewController

- (void)startApp
{
    self.pageControl.frame = CGRectMake(-SCREEN_WIDTH, -SCREEN_HEIGHT, 0, 0);
    [UIView animateWithDuration:1 animations:^{
        self.mainScrollview.frame = CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 0, 0);
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];

    NSLog(@"111");
    self.tripBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.tripBtn.frame = CGRectMake(30, 100, 100, 100);
    [self.tripBtn setTitle:@"trip" forState:UIControlStateNormal];
    [self.tripBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.tripBtn addTarget:self action:@selector(toTripview) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.tripBtn];
    
    self.radioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.radioBtn.frame = CGRectMake(30, 200, 100, 100);
    [self.radioBtn setTitle:@"radio" forState:UIControlStateNormal];
    [self.radioBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.radioBtn addTarget:self action:@selector(toRadioview) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.radioBtn];
    
    self.eyesBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.eyesBtn.frame = CGRectMake(30, 300, 100, 100);
    [self.eyesBtn setTitle:@"eyes" forState:UIControlStateNormal];
    [self.eyesBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.eyesBtn addTarget:self action:@selector(toEyesview) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.eyesBtn];
    
    self.magazineBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.magazineBtn.frame = CGRectMake(30, 400, 100, 100);
    [self.magazineBtn setTitle:@"magazine" forState:UIControlStateNormal];
    [self.magazineBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.magazineBtn addTarget:self action:@selector(toMagazineview) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.magazineBtn];
    
    self.aboutMeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.aboutMeBtn.frame = CGRectMake(30, 500, 100, 100);
    [self.aboutMeBtn setTitle:@"about me" forState:UIControlStateNormal];
    [self.aboutMeBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.aboutMeBtn addTarget:self action:@selector(toAboutMeview) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.aboutMeBtn];
    
    [self firstLunchApp];
  
}

- (void)firstLunchApp
{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
        
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
        // 布局轮播图
        self.mainScrollview = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
        self.mainScrollview.contentSize = CGSizeMake(SCREEN_WIDTH*4, SCREEN_HEIGHT);
        self.mainScrollview.pagingEnabled = YES;
        self.mainScrollview.bounces = NO;
        self.mainScrollview.showsHorizontalScrollIndicator = NO;
        self.mainScrollview.delegate = self;
        [self.view addSubview:self.mainScrollview];
        
        self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-20, SCREEN_WIDTH, 20)];
        self.pageControl.numberOfPages = 4;
        self.pageControl.currentPage = 0;
        self.pageControl.pageIndicatorTintColor = [UIColor grayColor];// 未选中的颜色
        self.pageControl.currentPageIndicatorTintColor = [UIColor blueColor];
        [self.view addSubview:self.pageControl];
        
        for (int i = 0; i<4; i++) {
            UIImageView *showImageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"main%d.JPG",i]]];
            showImageview.frame = CGRectMake(SCREEN_WIDTH*i, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            [self.mainScrollview addSubview:showImageview];
        }
        self.startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.startBtn.frame = CGRectMake(SCREEN_WIDTH*3, SCREEN_HEIGHT - 100,SCREEN_WIDTH/2-20 ,40);
        [self.startBtn setTitle:@"开启" forState:UIControlStateNormal];
        [self.startBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self.startBtn addTarget:self action:@selector(startApp) forControlEvents:UIControlEventTouchUpInside];
        [self.mainScrollview addSubview:self.startBtn];
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
        self.pageControl.currentPage = (int)(self.mainScrollview.contentOffset.x/SCREEN_WIDTH);
}
- (void)toTripview
{
    TravelMainViewController *travelMainVC = [[TravelMainViewController alloc]init];
    UINavigationController *travelNav = [[UINavigationController alloc]initWithRootViewController:travelMainVC];
    [self presentViewController:travelNav animated:YES completion:nil];
}
- (void)toRadioview
{
}
- (void)toEyesview
{
}
- (void)toMagazineview
{
    HQCollectionViewController *HQCollectionVC = [[HQCollectionViewController alloc] initWithNibName:@"HQCollectionViewController" bundle:nil];
    UINavigationController *MagezineNav = [[UINavigationController alloc] initWithRootViewController:HQCollectionVC];
    [self presentViewController:MagezineNav animated:YES completion:nil];
    
    
}
- (void)toAboutMeview
{
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
